package boxe.timer.manager;

/**
 * Manager to save or load the config using serialization
 * 
 * @author Julien Perriard
 * @date 25.05.2010
 *
 */

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import boxe.timer.Mode;
import boxe.timer.env.Propertie;
import boxe.timer.tools.XmlTools;

public class ConfigManager {

	
	/**
	 * Save the current config
	 * 
	 * @param listMode
	 */
	public void saveConfig(List<Mode> listMode) {
		try {
			new XmlTools().encodeToFile(listMode, Propertie.CONFIG_FILE);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * Load the current config
	 * 
	 */
	public List<Mode> loadConfig() {
		List<Mode> list = new ArrayList<Mode>();
		try {
			list = (List<Mode>) new XmlTools().decodeFromFile(Propertie.CONFIG_FILE);
			return list;
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
}

